﻿//===============================================================================
// Apolineo Patterns & Practices LeanEngine Framework
//===============================================================================
// Copyright © Apolineo Desenvolvimento de Sistemas Ltda.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================

using System;
using System.Windows.Forms;
using LeanEngine.SalesConcept.Entity;
using LeanEngine.Entity;
using LeanEngine.Extensions;
using System.ComponentModel;

namespace LeanEngine.SalesConcept.Windows.Control
{
    public partial class MaintenanceControlOfSalesman : UserControl, IMaintenanceControl<Salesman>
    {
        #region Constructor Members

        public MaintenanceControlOfSalesman()
        {
            InitializeComponent();
        }

        #endregion

        #region Property Members

        private Salesman CurrentSalesman { get; set; }

        [Browsable(false)]
        public string ErrorMessages
        {
            get { return this.propertyValidatorProvider1.ErrorMessages; }
        }

        #endregion

        #region IMaintenanceControl<Salesman> Members

        public Salesman GetControlsValues()
        {
            if (this.CurrentSalesman.IsNull()) this.CurrentSalesman = new Salesman();

            this.CurrentSalesman.Name = this.txtName.Text;
            this.CurrentSalesman.DocumentNumber = this.txtDocumentNumber.Text;
            this.CurrentSalesman.Birthdate = this.dtpBirthDate.Value;
            this.CurrentSalesman.BankAccountName = this.txtBankAccountName.Text;
            this.CurrentSalesman.BankAccountNumber = this.txtBankAccountNumber.Text;
            this.CurrentSalesman.BankAgency = this.txtBankAgency.Text;

            return this.CurrentSalesman;
        }

        public void SetControlsValues(Salesman value)
        {
            this.CurrentSalesman = value;

            this.txtName.Text = this.CurrentSalesman.Name;
            this.txtDocumentNumber.Text = this.CurrentSalesman.DocumentNumber;
            this.dtpBirthDate.Value = this.CurrentSalesman.Birthdate;
            this.txtBankAccountName.Text = this.CurrentSalesman.BankAccountName;
            this.txtBankAccountNumber.Text = this.CurrentSalesman.BankAccountNumber;
            this.txtBankAgency.Text = this.CurrentSalesman.BankAgency;
        }

        public void ClearControls()
        {
            this.txtName.Text = string.Empty;
            this.txtDocumentNumber.Text = string.Empty;
            this.dtpBirthDate.Value = new DateTime(1980, 1, 1);
            this.txtBankAccountName.Text = string.Empty;
            this.txtBankAccountNumber.Text = string.Empty;
            this.txtBankAgency.Text = string.Empty;

            this.txtName.Focus();
        }

        #endregion
    }
}
